package com.sds.module;

import com.google.inject.servlet.ServletModule;
import com.sds.ai.api.provider.DataProvider;
import com.sds.ai.impl.provider.AIMLResponseProvider;
import com.sds.ai.impl.provider.DataProviderImpl;
import com.sds.ai.module.CoreModule;
import com.sds.servlet.ChatServlet;
import com.sds.servlet.HelloWorldServlet;
import com.sds.servlet.ShowChatLogServlet;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class KimModule extends ServletModule {

    @Override
    protected void configureServlets() {
        BasicConfigurator.configure();
        Logger.getRootLogger().setLevel(Level.INFO);

        //bind instance
        bind(EntityManagerFactory.class).toInstance(Persistence.createEntityManagerFactory("kim-datasource"));
        bind(DataProvider.class).to(DataProviderImpl.class).asEagerSingleton();
        bind(AIMLResponseProvider.class).asEagerSingleton();

        install(new CoreModule());


        //bind servlet
        serve("/helloWorld").with(HelloWorldServlet.class);
        serve("/chat").with(ChatServlet.class);
        serve("/chatLog").with(ShowChatLogServlet.class);

        super.configureServlets();
    }
}
